package com.ylr.user.framework.service.impl;

import com.ylr.user.framework.entity.HistoryPasswordEntity;
import com.ylr.user.framework.mapper.HistoryPasswordMapper;
import com.ylr.user.framework.service.HistoryPasswordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2021-09-26 22:09:00
 * className: HistoryPasswordServiceImpl 用户历史密码操作请求服务接口实现类
 * version: 1.0
 * description:
 */
@Service("historyPasswordService")
public class HistoryPasswordServiceImpl extends ServiceImpl<HistoryPasswordMapper, HistoryPasswordEntity> implements HistoryPasswordService {

    private static final Logger log = LoggerFactory.getLogger(HistoryPasswordServiceImpl.class);

    @Override
    public void saveUserPassword(Long userId, String password) {

        HistoryPasswordEntity historyPassword = new HistoryPasswordEntity();
        historyPassword.setUserId(userId)
                .setPassword(password)
                .setCreateTime(new Date());
        // 保存用户使用的密码记录
        baseMapper.insert(historyPassword);
        log.info("保存用户密码记录完成");
    }

    @Override
    public Set<String> getLast3Password(Long userId) {
        return baseMapper.getLast3Password(userId);
    }
}